{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# <center>零售业数据分析系</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "项目背景\n",
    "- 此次项目数据来自Kaggle，包含了2010年12月1日至2011年12月9日在英国注册的非实体网上零售发生的所有交易。公司主要销售独特的全天候礼品。该公司的许多客户都是批发商。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 字段介绍\n",
    "- InvoiceNo: 订单编号，每笔交易有6个整数，退货订单编号开头有字母'C'。\n",
    "- StockCode: 产品编号，由5个整数组成。\n",
    "- Description: 产品描述。\n",
    "- Quantity: 产品数量，有负号的表示退货\n",
    "- InvoiceDate: 订单日期和时间。\n",
    "- UnitPrice: 单价（英镑），单位产品的价格。\n",
    "- CustomerID:客户编号，每个客户编号由5位数字组成。\n",
    "- Country: 国家的名称，每个客户所在国家/地区的名称。\n",
    "\n",
    "> 问题\n",
    "- 1.购买商品数前十的国家是？\n",
    "- 2.交易额前十的国家是？\n",
    "- 3.哪些月份销量较佳？\n",
    "- 4.客单价多少？\n",
    "- 5.用户消费行为分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar, Grid, Line,Scatter,Pie,Funnel\n",
    "#LIGHT DARK CHALK ESSOS PURPLE_PASSION\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "import json\n",
    "from pandas.io.json import json_normalize\n",
    "#设置中文标签的显示\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  #设置显示中文字体"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>536365</td>\n",
       "      <td>85123A</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>2.55</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>536365</td>\n",
       "      <td>84406B</td>\n",
       "      <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
       "      <td>8</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>2.75</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029G</td>\n",
       "      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029E</td>\n",
       "      <td>RED WOOLLY HOTTIE WHITE HEART.</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541904</th>\n",
       "      <td>581587</td>\n",
       "      <td>22613</td>\n",
       "      <td>PACK OF 20 SPACEBOY NAPKINS</td>\n",
       "      <td>12</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>0.85</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541905</th>\n",
       "      <td>581587</td>\n",
       "      <td>22899</td>\n",
       "      <td>CHILDREN'S APRON DOLLY GIRL</td>\n",
       "      <td>6</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>2.10</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541906</th>\n",
       "      <td>581587</td>\n",
       "      <td>23254</td>\n",
       "      <td>CHILDRENS CUTLERY DOLLY GIRL</td>\n",
       "      <td>4</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541907</th>\n",
       "      <td>581587</td>\n",
       "      <td>23255</td>\n",
       "      <td>CHILDRENS CUTLERY CIRCUS PARADE</td>\n",
       "      <td>4</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541908</th>\n",
       "      <td>581587</td>\n",
       "      <td>22138</td>\n",
       "      <td>BAKING SET 9 PIECE RETROSPOT</td>\n",
       "      <td>3</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.95</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>541909 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       InvoiceNo StockCode                          Description  Quantity  \\\n",
       "0         536365    85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n",
       "1         536365     71053                  WHITE METAL LANTERN         6   \n",
       "2         536365    84406B       CREAM CUPID HEARTS COAT HANGER         8   \n",
       "3         536365    84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n",
       "4         536365    84029E       RED WOOLLY HOTTIE WHITE HEART.         6   \n",
       "...          ...       ...                                  ...       ...   \n",
       "541904    581587     22613          PACK OF 20 SPACEBOY NAPKINS        12   \n",
       "541905    581587     22899         CHILDREN'S APRON DOLLY GIRL          6   \n",
       "541906    581587     23254        CHILDRENS CUTLERY DOLLY GIRL          4   \n",
       "541907    581587     23255      CHILDRENS CUTLERY CIRCUS PARADE         4   \n",
       "541908    581587     22138        BAKING SET 9 PIECE RETROSPOT          3   \n",
       "\n",
       "            InvoiceDate  UnitPrice CustomerID         Country  \n",
       "0        12/1/2010 8:26       2.55    17850.0  United Kingdom  \n",
       "1        12/1/2010 8:26       3.39    17850.0  United Kingdom  \n",
       "2        12/1/2010 8:26       2.75    17850.0  United Kingdom  \n",
       "3        12/1/2010 8:26       3.39    17850.0  United Kingdom  \n",
       "4        12/1/2010 8:26       3.39    17850.0  United Kingdom  \n",
       "...                 ...        ...        ...             ...  \n",
       "541904  12/9/2011 12:50       0.85    12680.0          France  \n",
       "541905  12/9/2011 12:50       2.10    12680.0          France  \n",
       "541906  12/9/2011 12:50       4.15    12680.0          France  \n",
       "541907  12/9/2011 12:50       4.15    12680.0          France  \n",
       "541908  12/9/2011 12:50       4.95    12680.0          France  \n",
       "\n",
       "[541909 rows x 8 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "film_date=pd.read_csv(\"data.csv\",encoding=\"utf-8\",dtype = {'Country' : str,\"Quantity\":np.int64,\"CustomerID\":str},low_memory=False)\n",
    "film_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#查看各行的控制情况\n",
    "film_date.isnull().any(axis=0)\n",
    "#删除存在的空行数据\n",
    "film_date.dropna(axis=0,how='any',inplace=True)\n",
    "\n",
    "# film_date.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>536365</td>\n",
       "      <td>22752</td>\n",
       "      <td>SET 7 BABUSHKA NESTING BOXES</td>\n",
       "      <td>2</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>7.65</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>536365</td>\n",
       "      <td>21730</td>\n",
       "      <td>GLASS STAR FROSTED T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>4.25</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>536366</td>\n",
       "      <td>22633</td>\n",
       "      <td>HAND WARMER UNION JACK</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:28</td>\n",
       "      <td>1.85</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>536366</td>\n",
       "      <td>22632</td>\n",
       "      <td>HAND WARMER RED POLKA DOT</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:28</td>\n",
       "      <td>1.85</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541904</th>\n",
       "      <td>581587</td>\n",
       "      <td>22613</td>\n",
       "      <td>PACK OF 20 SPACEBOY NAPKINS</td>\n",
       "      <td>12</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>0.85</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541905</th>\n",
       "      <td>581587</td>\n",
       "      <td>22899</td>\n",
       "      <td>CHILDREN'S APRON DOLLY GIRL</td>\n",
       "      <td>6</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>2.10</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541906</th>\n",
       "      <td>581587</td>\n",
       "      <td>23254</td>\n",
       "      <td>CHILDRENS CUTLERY DOLLY GIRL</td>\n",
       "      <td>4</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541907</th>\n",
       "      <td>581587</td>\n",
       "      <td>23255</td>\n",
       "      <td>CHILDRENS CUTLERY CIRCUS PARADE</td>\n",
       "      <td>4</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541908</th>\n",
       "      <td>581587</td>\n",
       "      <td>22138</td>\n",
       "      <td>BAKING SET 9 PIECE RETROSPOT</td>\n",
       "      <td>3</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.95</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>487036 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       InvoiceNo StockCode                        Description  Quantity  \\\n",
       "1         536365     71053                WHITE METAL LANTERN         6   \n",
       "5         536365     22752       SET 7 BABUSHKA NESTING BOXES         2   \n",
       "6         536365     21730  GLASS STAR FROSTED T-LIGHT HOLDER         6   \n",
       "7         536366     22633             HAND WARMER UNION JACK         6   \n",
       "8         536366     22632          HAND WARMER RED POLKA DOT         6   \n",
       "...          ...       ...                                ...       ...   \n",
       "541904    581587     22613        PACK OF 20 SPACEBOY NAPKINS        12   \n",
       "541905    581587     22899       CHILDREN'S APRON DOLLY GIRL          6   \n",
       "541906    581587     23254      CHILDRENS CUTLERY DOLLY GIRL          4   \n",
       "541907    581587     23255    CHILDRENS CUTLERY CIRCUS PARADE         4   \n",
       "541908    581587     22138      BAKING SET 9 PIECE RETROSPOT          3   \n",
       "\n",
       "            InvoiceDate  UnitPrice CustomerID         Country  \n",
       "1        12/1/2010 8:26       3.39    17850.0  United Kingdom  \n",
       "5        12/1/2010 8:26       7.65    17850.0  United Kingdom  \n",
       "6        12/1/2010 8:26       4.25    17850.0  United Kingdom  \n",
       "7        12/1/2010 8:28       1.85    17850.0  United Kingdom  \n",
       "8        12/1/2010 8:28       1.85    17850.0  United Kingdom  \n",
       "...                 ...        ...        ...             ...  \n",
       "541904  12/9/2011 12:50       0.85    12680.0          France  \n",
       "541905  12/9/2011 12:50       2.10    12680.0          France  \n",
       "541906  12/9/2011 12:50       4.15    12680.0          France  \n",
       "541907  12/9/2011 12:50       4.15    12680.0          France  \n",
       "541908  12/9/2011 12:50       4.95    12680.0          France  \n",
       "\n",
       "[487036 rows x 8 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 产品编号---保证产品编号是5位纯数字\n",
    "film_date=film_date[film_date.loc[:,'StockCode'].apply(lambda x: x.isdigit())]\n",
    "\n",
    "# film_date=film_date[film_date[\"产品编号\"].apply(lambda x: x.isdigit())]\n",
    "film_date\n",
    "# film_date\n",
    "# film_date.to_csv(\"shuju.csv\",encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\program files\\python\\lib\\site-packages\\ipykernel_launcher.py:4: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  after removing the cwd from sys.path.\n",
      "d:\\program files\\python\\lib\\site-packages\\ipykernel_launcher.py:6: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \n",
      "d:\\program files\\python\\lib\\site-packages\\pandas\\core\\indexing.py:1743: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  isetter(ilocs[0], value)\n"
     ]
    }
   ],
   "source": [
    "#对日期数据进行处理\n",
    "# film_date.loc[:,'订单日期和时间']=pd.to_datetime(film_date['订单日期和时间'], format='%m/%d/%Y %H:%M')\n",
    "#对产品数量的数据类型进行处理\n",
    "film_date['InvoiceDate'] = pd.to_datetime(film_date['InvoiceDate'])\n",
    "film_date['InvoiceDate']\n",
    "film_date['InvoiceDate'] = film_date['InvoiceDate'].dt.date\n",
    "film_date.head(200)\n",
    "film_date.loc[:,\"Quantity\"]=film_date[\"Quantity\"].astype(np.int64)\n",
    "# film_date.loc[:,\"国家的名称\"]=film_date[\"国家的名称\"].astype(np.string_)\n",
    "# film_date.to_csv(\"shuju.csv\",encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InvoiceNo</th>\n",
       "      <th>StockCode</th>\n",
       "      <th>Description</th>\n",
       "      <th>Quantity</th>\n",
       "      <th>InvoiceDate</th>\n",
       "      <th>UnitPrice</th>\n",
       "      <th>CustomerID</th>\n",
       "      <th>Country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>536365</td>\n",
       "      <td>22752</td>\n",
       "      <td>SET 7 BABUSHKA NESTING BOXES</td>\n",
       "      <td>2</td>\n",
       "      <td>2010-12-01</td>\n",
       "      <td>7.65</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>536365</td>\n",
       "      <td>21730</td>\n",
       "      <td>GLASS STAR FROSTED T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01</td>\n",
       "      <td>4.25</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>536366</td>\n",
       "      <td>22633</td>\n",
       "      <td>HAND WARMER UNION JACK</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01</td>\n",
       "      <td>1.85</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>536366</td>\n",
       "      <td>22632</td>\n",
       "      <td>HAND WARMER RED POLKA DOT</td>\n",
       "      <td>6</td>\n",
       "      <td>2010-12-01</td>\n",
       "      <td>1.85</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541904</th>\n",
       "      <td>581587</td>\n",
       "      <td>22613</td>\n",
       "      <td>PACK OF 20 SPACEBOY NAPKINS</td>\n",
       "      <td>12</td>\n",
       "      <td>2011-12-09</td>\n",
       "      <td>0.85</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541905</th>\n",
       "      <td>581587</td>\n",
       "      <td>22899</td>\n",
       "      <td>CHILDREN'S APRON DOLLY GIRL</td>\n",
       "      <td>6</td>\n",
       "      <td>2011-12-09</td>\n",
       "      <td>2.10</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541906</th>\n",
       "      <td>581587</td>\n",
       "      <td>23254</td>\n",
       "      <td>CHILDRENS CUTLERY DOLLY GIRL</td>\n",
       "      <td>4</td>\n",
       "      <td>2011-12-09</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541907</th>\n",
       "      <td>581587</td>\n",
       "      <td>23255</td>\n",
       "      <td>CHILDRENS CUTLERY CIRCUS PARADE</td>\n",
       "      <td>4</td>\n",
       "      <td>2011-12-09</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541908</th>\n",
       "      <td>581587</td>\n",
       "      <td>22138</td>\n",
       "      <td>BAKING SET 9 PIECE RETROSPOT</td>\n",
       "      <td>3</td>\n",
       "      <td>2011-12-09</td>\n",
       "      <td>4.95</td>\n",
       "      <td>12680.0</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>487036 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       InvoiceNo StockCode                        Description  Quantity  \\\n",
       "1         536365     71053                WHITE METAL LANTERN         6   \n",
       "5         536365     22752       SET 7 BABUSHKA NESTING BOXES         2   \n",
       "6         536365     21730  GLASS STAR FROSTED T-LIGHT HOLDER         6   \n",
       "7         536366     22633             HAND WARMER UNION JACK         6   \n",
       "8         536366     22632          HAND WARMER RED POLKA DOT         6   \n",
       "...          ...       ...                                ...       ...   \n",
       "541904    581587     22613        PACK OF 20 SPACEBOY NAPKINS        12   \n",
       "541905    581587     22899       CHILDREN'S APRON DOLLY GIRL          6   \n",
       "541906    581587     23254      CHILDRENS CUTLERY DOLLY GIRL          4   \n",
       "541907    581587     23255    CHILDRENS CUTLERY CIRCUS PARADE         4   \n",
       "541908    581587     22138      BAKING SET 9 PIECE RETROSPOT          3   \n",
       "\n",
       "       InvoiceDate  UnitPrice CustomerID         Country  \n",
       "1       2010-12-01       3.39    17850.0  United Kingdom  \n",
       "5       2010-12-01       7.65    17850.0  United Kingdom  \n",
       "6       2010-12-01       4.25    17850.0  United Kingdom  \n",
       "7       2010-12-01       1.85    17850.0  United Kingdom  \n",
       "8       2010-12-01       1.85    17850.0  United Kingdom  \n",
       "...            ...        ...        ...             ...  \n",
       "541904  2011-12-09       0.85    12680.0          France  \n",
       "541905  2011-12-09       2.10    12680.0          France  \n",
       "541906  2011-12-09       4.15    12680.0          France  \n",
       "541907  2011-12-09       4.15    12680.0          France  \n",
       "541908  2011-12-09       4.95    12680.0          France  \n",
       "\n",
       "[487036 rows x 8 columns]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=film_date\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 1.购买商品数前十的国家是？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>Quantity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>3905570</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Netherlands</td>\n",
       "      <td>193063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>EIRE</td>\n",
       "      <td>133616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Germany</td>\n",
       "      <td>109899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>France</td>\n",
       "      <td>105522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Australia</td>\n",
       "      <td>81541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Sweden</td>\n",
       "      <td>35113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Switzerland</td>\n",
       "      <td>28090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Japan</td>\n",
       "      <td>24561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Spain</td>\n",
       "      <td>22548</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Country  Quantity\n",
       "0  United Kingdom   3905570\n",
       "1     Netherlands    193063\n",
       "2            EIRE    133616\n",
       "3         Germany    109899\n",
       "4          France    105522\n",
       "5       Australia     81541\n",
       "6          Sweden     35113\n",
       "7     Switzerland     28090\n",
       "8           Japan     24561\n",
       "9           Spain     22548"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#通过国家和产品数量来统计得出排名前十的国家\n",
    "\n",
    "list=data.groupby(\"Country\",as_index=False)[\"Quantity\"].sum()\n",
    "list.sort_values(by=\"Quantity\",ascending=False,inplace=True)\n",
    "list=list.head(10).reset_index().drop(\"index\",axis=1)\n",
    "type(list)\n",
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"52d92ffea969410399e1a74787dab02d\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_52d92ffea969410399e1a74787dab02d = echarts.init(\n",
       "                    document.getElementById('52d92ffea969410399e1a74787dab02d'), 'white', {renderer: 'canvas'});\n",
       "                var option_52d92ffea969410399e1a74787dab02d = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u5546\\u54c1\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"United Kingdom\",\n",
       "                    \"value\": 3905570\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Netherlands\",\n",
       "                    \"value\": 193063\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"EIRE\",\n",
       "                    \"value\": 133616\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Germany\",\n",
       "                    \"value\": 109899\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"France\",\n",
       "                    \"value\": 105522\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Australia\",\n",
       "                    \"value\": 81541\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Sweden\",\n",
       "                    \"value\": 35113\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Switzerland\",\n",
       "                    \"value\": 28090\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Japan\",\n",
       "                    \"value\": 24561\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Spain\",\n",
       "                    \"value\": 22548\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"ascending\",\n",
       "            \"gap\": 0,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"Sweden\",\n",
       "                \"Japan\",\n",
       "                \"France\",\n",
       "                \"United Kingdom\",\n",
       "                \"EIRE\",\n",
       "                \"Spain\",\n",
       "                \"Germany\",\n",
       "                \"Netherlands\",\n",
       "                \"Australia\",\n",
       "                \"Switzerland\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"United Kingdom\": true,\n",
       "                \"Netherlands\": true,\n",
       "                \"EIRE\": true,\n",
       "                \"Germany\": true,\n",
       "                \"France\": true,\n",
       "                \"Australia\": true,\n",
       "                \"Sweden\": true,\n",
       "                \"Switzerland\": true,\n",
       "                \"Japan\": true,\n",
       "                \"Spain\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u5168\\u5e74\\u5546\\u54c1\\u524d\\u5341\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_52d92ffea969410399e1a74787dab02d.setOption(option_52d92ffea969410399e1a74787dab02d);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x139d73d0>"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#漏斗图\n",
    "funnel=Funnel().add(\n",
    "        \"商品\",\n",
    "        list.values.tolist(),\n",
    "    sort_=\"ascending\",\n",
    "    ).set_global_opts(title_opts=opts.TitleOpts(title=\"全年商品前十\"),legend_opts=opts.LegendOpts(\n",
    "                orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"\n",
    "            ))\n",
    "funnel.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['United Kingdom',\n",
       " 'Netherlands',\n",
       " 'EIRE',\n",
       " 'Germany',\n",
       " 'France',\n",
       " 'Australia',\n",
       " 'Sweden',\n",
       " 'Switzerland',\n",
       " 'Japan',\n",
       " 'Spain']"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(list[\"Country\"]).tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'essos':'https://assets.pyecharts.org/assets/themes/essos'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"763eca3c1ebd4393a7e3113de49dee2c\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'essos'], function(echarts) {\n",
       "                var chart_763eca3c1ebd4393a7e3113de49dee2c = echarts.init(\n",
       "                    document.getElementById('763eca3c1ebd4393a7e3113de49dee2c'), 'essos', {renderer: 'canvas'});\n",
       "                var option_763eca3c1ebd4393a7e3113de49dee2c = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\",\n",
       "            \"data\": [\n",
       "                3905570,\n",
       "                193063,\n",
       "                133616,\n",
       "                109899,\n",
       "                105522,\n",
       "                81541,\n",
       "                35113,\n",
       "                28090,\n",
       "                24561,\n",
       "                22548\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\",\n",
       "                        \"symbolSize\": [\n",
       "                            90,\n",
       "                            70\n",
       "                        ]\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\",\n",
       "                        \"symbolSize\": [\n",
       "                            90,\n",
       "                            70\n",
       "                        ]\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\",\n",
       "                        \"symbolSize\": [\n",
       "                            90,\n",
       "                            70\n",
       "                        ]\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u56fd\\u5bb6\\u7684\\u540d\\u79f0\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"United Kingdom\",\n",
       "                \"Netherlands\",\n",
       "                \"EIRE\",\n",
       "                \"Germany\",\n",
       "                \"France\",\n",
       "                \"Australia\",\n",
       "                \"Sweden\",\n",
       "                \"Switzerland\",\n",
       "                \"Japan\",\n",
       "                \"Spain\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u4ea7\\u54c1\\u6570\\u91cf\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"itemSize\": 15,\n",
       "        \"itemGap\": 10,\n",
       "        \"left\": \"80%\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"type\": \"png\",\n",
       "                \"backgroundColor\": \"auto\",\n",
       "                \"connectedBackgroundColor\": \"#fff\",\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4fdd\\u5b58\\u4e3a\\u56fe\\u7247\",\n",
       "                \"pixelRatio\": 1\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u8fd8\\u539f\"\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                \"readOnly\": false,\n",
       "                \"lang\": [\n",
       "                    \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                    \"\\u5173\\u95ed\",\n",
       "                    \"\\u5237\\u65b0\"\n",
       "                ],\n",
       "                \"backgroundColor\": \"#fff\",\n",
       "                \"textareaColor\": \"#fff\",\n",
       "                \"textareaBorderColor\": \"#333\",\n",
       "                \"textColor\": \"#000\",\n",
       "                \"buttonColor\": \"#c23531\",\n",
       "                \"buttonTextColor\": \"#fff\"\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u533a\\u57df\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u5207\\u6362\\u4e3a\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u5207\\u6362\\u4e3a\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5207\\u6362\\u4e3a\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5207\\u6362\\u4e3a\\u5e73\\u94fa\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            },\n",
       "            \"brush\": {\n",
       "                \"icon\": {},\n",
       "                \"title\": {\n",
       "                    \"rect\": \"\\u77e9\\u5f62\\u9009\\u62e9\",\n",
       "                    \"polygon\": \"\\u5708\\u9009\",\n",
       "                    \"lineX\": \"\\u6a2a\\u5411\\u9009\\u62e9\",\n",
       "                    \"lineY\": \"\\u7eb5\\u5411\\u9009\\u62e9\",\n",
       "                    \"keep\": \"\\u4fdd\\u6301\\u9009\\u62e9\",\n",
       "                    \"clear\": \"\\u6e05\\u9664\\u9009\\u62e9\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"realtime\": true,\n",
       "        \"start\": 20,\n",
       "        \"end\": 80,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false\n",
       "    }\n",
       "};\n",
       "                chart_763eca3c1ebd4393a7e3113de49dee2c.setOption(option_763eca3c1ebd4393a7e3113de49dee2c);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x13ba8030>"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.ESSOS))\n",
    "bar.add_xaxis(np.array(list[\"Country\"]).tolist())\n",
    "bar.add_yaxis(\"排名前十的国家\",np.array(list[\"Quantity\"]).tolist())\n",
    "#设置全局配置\n",
    "bar.set_global_opts(title_opts=opts.TitleOpts(title=\"排名前十的国家\"),\n",
    "                    toolbox_opts=opts.ToolboxOpts(),\n",
    "                    datazoom_opts=opts.DataZoomOpts(is_show=True),\n",
    "                   yaxis_opts=opts.AxisOpts(\n",
    "                    name='产品数量'),\n",
    "                    xaxis_opts=opts.AxisOpts(\n",
    "                    name='国家的名称')\n",
    "                   )\n",
    "#设置系列配置label_opts=opts.LabelOpts(font_size=20,font_style=\"italic\"),\n",
    "bar.set_series_opts(\n",
    "                    label_opts=opts.LabelOpts(is_show=False),\n",
    "                    markpoint_opts=opts.MarkPointOpts(\n",
    "                data=[\n",
    "                    opts.MarkPointItem(type_=\"max\", name=\"最大值\",symbol_size=[90, 70]),\n",
    "                    opts.MarkPointItem(type_=\"min\", name=\"最小值\",symbol_size=[90, 70]),\n",
    "                    opts.MarkPointItem(type_=\"average\", name=\"平均值\",symbol_size=[90, 70]),\n",
    "                    \n",
    "                ]\n",
    "            ))\n",
    "\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'essos':'https://assets.pyecharts.org/assets/themes/essos'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"7d5752b616bd469c843b18a89c70f600\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'essos'], function(echarts) {\n",
       "                var chart_7d5752b616bd469c843b18a89c70f600 = echarts.init(\n",
       "                    document.getElementById('7d5752b616bd469c843b18a89c70f600'), 'essos', {renderer: 'canvas'});\n",
       "                var option_7d5752b616bd469c843b18a89c70f600 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"United Kingdom\",\n",
       "                    \"value\": 3661496\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Netherlands\",\n",
       "                    \"value\": 193063\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"EIRE\",\n",
       "                    \"value\": 127576\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Germany\",\n",
       "                    \"value\": 109899\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"France\",\n",
       "                    \"value\": 104899\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Australia\",\n",
       "                    \"value\": 81541\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Sweden\",\n",
       "                    \"value\": 35113\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Switzerland\",\n",
       "                    \"value\": 27554\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Japan\",\n",
       "                    \"value\": 24561\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Spain\",\n",
       "                    \"value\": 22548\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"0%\",\n",
       "                \"75%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"United Kingdom\",\n",
       "                \"Netherlands\",\n",
       "                \"EIRE\",\n",
       "                \"Germany\",\n",
       "                \"France\",\n",
       "                \"Australia\",\n",
       "                \"Sweden\",\n",
       "                \"Switzerland\",\n",
       "                \"Japan\",\n",
       "                \"Spain\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u9500\\u552e\\u989d\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_7d5752b616bd469c843b18a89c70f600.setOption(option_7d5752b616bd469c843b18a89c70f600);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x13bacd50>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#饼图 \n",
    "pie=Pie(init_opts=opts.InitOpts(theme=ThemeType.ESSOS)).add(\"\",list.values.tolist())\n",
    "pie.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "pie.set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"销售额排名前十的国家\"),\n",
    "            legend_opts=opts.LegendOpts(\n",
    "                orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"\n",
    "            ),\n",
    "        )\n",
    "pie.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 2. 交易额前十的国家是？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\program files\\python\\lib\\site-packages\\pandas\\core\\indexing.py:1743: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  isetter(ilocs[0], value)\n",
      "d:\\program files\\python\\lib\\site-packages\\pandas\\core\\indexing.py:1596: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  self.obj[key] = _infer_fill_value(value)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>国家的名称</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>6.202993e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Netherlands</td>\n",
       "      <td>2.689354e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>EIRE</td>\n",
       "      <td>2.333032e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Germany</td>\n",
       "      <td>1.855734e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>France</td>\n",
       "      <td>1.711794e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Australia</td>\n",
       "      <td>1.328914e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Switzerland</td>\n",
       "      <td>4.754403e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Spain</td>\n",
       "      <td>3.987988e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Sweden</td>\n",
       "      <td>3.465363e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Belgium</td>\n",
       "      <td>3.459105e+04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            国家的名称           销售额\n",
       "0  United Kingdom  6.202993e+06\n",
       "1     Netherlands  2.689354e+05\n",
       "2            EIRE  2.333032e+05\n",
       "3         Germany  1.855734e+05\n",
       "4          France  1.711794e+05\n",
       "5       Australia  1.328914e+05\n",
       "6     Switzerland  4.754403e+04\n",
       "7           Spain  3.987988e+04\n",
       "8          Sweden  3.465363e+04\n",
       "9         Belgium  3.459105e+04"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#通过产品数量和单价计算出销售额，排序之后得出排名前十的国家\n",
    "film_date.loc[:,\"单价（英镑）\"]=film_date[\"单价（英镑）\"].astype(np.float64)\n",
    "film_date.loc[:,\"销售额\"]=film_date[\"产品数量\"]*film_date[\"单价（英镑）\"]\n",
    "list_sales=film_date.groupby(film_date[\"国家的名称\"],as_index=False)[\"销售额\"].sum()\n",
    "list_sales=list_sales.sort_values(by=\"销售额\",ascending=False)\n",
    "list_sales=list_sales.head(10).reset_index().drop(\"index\",axis=1)\n",
    "list_sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'essos':'https://assets.pyecharts.org/assets/themes/essos'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"fb62008cbc8843e79dd7c76ae24f7d4a\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'essos'], function(echarts) {\n",
       "                var chart_fb62008cbc8843e79dd7c76ae24f7d4a = echarts.init(\n",
       "                    document.getElementById('fb62008cbc8843e79dd7c76ae24f7d4a'), 'essos', {renderer: 'canvas'});\n",
       "                var option_fb62008cbc8843e79dd7c76ae24f7d4a = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u9500\\u552e\\u989d\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\",\n",
       "            \"data\": [\n",
       "                6202993.28,\n",
       "                268935.38,\n",
       "                233303.19,\n",
       "                185573.36,\n",
       "                171179.37,\n",
       "                132891.39,\n",
       "                47544.03,\n",
       "                39879.88,\n",
       "                34653.63,\n",
       "                34591.05\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"fontSize\": 20,\n",
       "                \"fontStyle\": \"italic\"\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"silent\": false,\n",
       "                \"precision\": 2,\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"top\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u5e73\\u5747\\u503c\",\n",
       "                        \"type\": \"average\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u9500\\u552e\\u989d\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u9500\\u552e\\u989d\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u56fd\\u5bb6\\u7684\\u540d\\u79f0\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"United Kingdom\",\n",
       "                \"Netherlands\",\n",
       "                \"EIRE\",\n",
       "                \"Germany\",\n",
       "                \"France\",\n",
       "                \"Australia\",\n",
       "                \"Switzerland\",\n",
       "                \"Spain\",\n",
       "                \"Sweden\",\n",
       "                \"Belgium\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u9500\\u552e\\u989d(\\u82f1\\u9551)\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4ea4\\u6613\\u989d\\u6392\\u540d\\u524d\\u5341\\u7684\\u56fd\\u5bb6\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"itemSize\": 15,\n",
       "        \"itemGap\": 10,\n",
       "        \"left\": \"80%\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"type\": \"png\",\n",
       "                \"backgroundColor\": \"auto\",\n",
       "                \"connectedBackgroundColor\": \"#fff\",\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4fdd\\u5b58\\u4e3a\\u56fe\\u7247\",\n",
       "                \"pixelRatio\": 1\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u8fd8\\u539f\"\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                \"readOnly\": false,\n",
       "                \"lang\": [\n",
       "                    \"\\u6570\\u636e\\u89c6\\u56fe\",\n",
       "                    \"\\u5173\\u95ed\",\n",
       "                    \"\\u5237\\u65b0\"\n",
       "                ],\n",
       "                \"backgroundColor\": \"#fff\",\n",
       "                \"textareaColor\": \"#fff\",\n",
       "                \"textareaBorderColor\": \"#333\",\n",
       "                \"textColor\": \"#000\",\n",
       "                \"buttonColor\": \"#c23531\",\n",
       "                \"buttonTextColor\": \"#fff\"\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u533a\\u57df\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u5207\\u6362\\u4e3a\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u5207\\u6362\\u4e3a\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5207\\u6362\\u4e3a\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5207\\u6362\\u4e3a\\u5e73\\u94fa\"\n",
       "                },\n",
       "                \"icon\": {}\n",
       "            },\n",
       "            \"brush\": {\n",
       "                \"icon\": {},\n",
       "                \"title\": {\n",
       "                    \"rect\": \"\\u77e9\\u5f62\\u9009\\u62e9\",\n",
       "                    \"polygon\": \"\\u5708\\u9009\",\n",
       "                    \"lineX\": \"\\u6a2a\\u5411\\u9009\\u62e9\",\n",
       "                    \"lineY\": \"\\u7eb5\\u5411\\u9009\\u62e9\",\n",
       "                    \"keep\": \"\\u4fdd\\u6301\\u9009\\u62e9\",\n",
       "                    \"clear\": \"\\u6e05\\u9664\\u9009\\u62e9\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"realtime\": true,\n",
       "        \"start\": 20,\n",
       "        \"end\": 80,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false\n",
       "    }\n",
       "};\n",
       "                chart_fb62008cbc8843e79dd7c76ae24f7d4a.setOption(option_fb62008cbc8843e79dd7c76ae24f7d4a);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x13ba5610>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#柱形图\n",
    "bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.ESSOS))\n",
    "bar.add_xaxis(np.array(list_sales[\"国家的名称\"]).tolist())\n",
    "bar.add_yaxis(\"销售额排名前十的国家\",np.array(list_sales[\"销售额\"]).round(2).tolist())\n",
    "bar.set_global_opts(title_opts=opts.TitleOpts(title=\"交易额排名前十的国家\"),\n",
    "                    toolbox_opts=opts.ToolboxOpts(),\n",
    "                    datazoom_opts=opts.DataZoomOpts(is_show=True),\n",
    "                   yaxis_opts=opts.AxisOpts(\n",
    "                    name='销售额(英镑)'),\n",
    "                    xaxis_opts=opts.AxisOpts(\n",
    "                    name='国家的名称')\n",
    "                   )\n",
    "bar.set_series_opts(label_opts=opts.LabelOpts(font_size=20,font_style=\"italic\"),\n",
    "            markline_opts=opts.MarkLineOpts(\n",
    "                data=[\n",
    "                    opts.MarkLineItem(type_=\"max\", name=\"最大值\"),\n",
    "                    opts.MarkLineItem(type_=\"min\", name=\"最小值\"),\n",
    "                    opts.MarkLineItem(type_=\"average\", name=\"平均值\"),\n",
    "                ]\n",
    "            ))\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 3.哪些月份销量较佳？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'film' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-23-5bf66ca6ead9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;31m# film=film_date\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mfilm\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'订单日期和时间'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfilm\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'订单日期和时间'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdate\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m \u001b[1;31m#将日期转换成str，然后取出年月\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[0mfilm\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'订单日期和时间'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfilm\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'订单日期和时间'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'film' is not defined"
     ]
    }
   ],
   "source": [
    "#去掉日期的时分秒精度\n",
    "# film=film_date\n",
    "\n",
    "film['订单日期和时间']=film['订单日期和时间'].dt.date\n",
    "#将日期转换成str，然后取出年月\n",
    "film['订单日期和时间']=film['订单日期和时间'].astype(np.str)\n",
    "film['订单日期和时间']=film['订单日期和时间'].str[:7]\n",
    "#进行求和，排序并重新建立索引\n",
    "list_month_sales=film.groupby(film[\"订单日期和时间\"],as_index=False)[\"产品数量\"].sum()\n",
    "list_month_sales=list_month_sales.sort_values(by=\"产品数量\",ascending=False)\n",
    "list_month_sales=list_month_sales.reset_index().drop(\"index\",axis=1)\n",
    "list_month_sales\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "type(list_month_sales)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'list_month_sales' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-52-98dda71a8f41>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#条形图\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mLine\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mInitOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtheme\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mThemeType\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mESSOS\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mline\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_xaxis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist_month_sales\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"订单日期和时间\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m \u001b[0mline\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_yaxis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"2010年12月到2011年12月的产品数量\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist_month_sales\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"产品数量\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mround\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m line.set_global_opts(title_opts=opts.TitleOpts(title=\"2010年12月到2011年12月的产品数量\"),\n",
      "\u001b[1;31mNameError\u001b[0m: name 'list_month_sales' is not defined"
     ]
    }
   ],
   "source": [
    "#条形图\n",
    "line = Line(init_opts=opts.InitOpts(theme=ThemeType.ESSOS))\n",
    "line.add_xaxis(np.array(list_month_sales[\"订单日期和时间\"]).tolist())\n",
    "line.add_yaxis(\"2010年12月到2011年12月的产品数量\",np.array(list_month_sales[\"产品数量\"]).round(2).tolist())\n",
    "line.set_global_opts(title_opts=opts.TitleOpts(title=\"2010年12月到2011年12月的产品数量\"),\n",
    "                    toolbox_opts=opts.ToolboxOpts(),\n",
    "                    datazoom_opts=opts.DataZoomOpts(is_show=True),\n",
    "                   yaxis_opts=opts.AxisOpts(\n",
    "                    name='产品数量'),\n",
    "                    xaxis_opts=opts.AxisOpts(\n",
    "                    name='订单日期和时间')\n",
    "                   )\n",
    "line.set_series_opts(label_opts=opts.LabelOpts(font_size=20,font_style=\"italic\"),\n",
    "            markline_opts=opts.MarkLineOpts(\n",
    "                data=[\n",
    "                    opts.MarkLineItem(type_=\"max\", name=\"最大值\"),\n",
    "                    opts.MarkLineItem(type_=\"min\", name=\"最小值\"),\n",
    "                    opts.MarkLineItem(type_=\"average\", name=\"平均值\"),\n",
    "                ]\n",
    "            ))\n",
    "line.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'list_month_sales' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-53-ce776ed8d21f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#饼图\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mpie\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mPie\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mInitOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtheme\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mThemeType\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mESSOS\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlist_month_sales\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mpie\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_series_opts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mLabelOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mis_show\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m pie.set_global_opts(\n\u001b[0;32m      5\u001b[0m             \u001b[0mtitle_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTitleOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtitle\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"2010年12月到2011年12月的产品数量\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'list_month_sales' is not defined"
     ]
    }
   ],
   "source": [
    "#饼图 \n",
    "pie=Pie(init_opts=opts.InitOpts(theme=ThemeType.ESSOS)).add(\"\",list_month_sales.values.tolist())\n",
    "pie.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "pie.set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"2010年12月到2011年12月的产品数量\"),\n",
    "            legend_opts=opts.LegendOpts(\n",
    "                orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"\n",
    "            ),\n",
    "        )\n",
    "pie.render_notebook()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'list_month_sales' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-54-8341514b9c9c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m pie=Pie().add(\n\u001b[0;32m      2\u001b[0m             \u001b[1;34m\"\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m             \u001b[0mlist_month_sales\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m             \u001b[0mradius\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"30%\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"75%\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m             \u001b[0mcenter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"50%\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"60%\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'list_month_sales' is not defined"
     ]
    }
   ],
   "source": [
    "pie=Pie().add(\n",
    "            \"\",\n",
    "            list_month_sales.values.tolist(),\n",
    "            radius=[\"30%\", \"75%\"],\n",
    "            center=[\"50%\", \"60%\"],\n",
    "            rosetype=\"area\"\n",
    "        ).set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"2010年12月到2011年12月的产品数量\"),\n",
    "            legend_opts=opts.LegendOpts(\n",
    "                orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"\n",
    "            )\n",
    "        )\n",
    "pie.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 4.客单价多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\program files\\python\\lib\\site-packages\\ipykernel_launcher.py:3: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "20.4"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#用销售总额除以顾客数得出客单价\n",
    "price=film_date[\"销售额\"].sum()\n",
    "film_date[\"客户编号\"]=film_date[\"客户编号\"].drop_duplicates().reset_index().drop('index',axis=1)\n",
    "user=len(film_date[\"客户编号\"])\n",
    "user_price=(price/user).round(2)\n",
    "user_price"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 5.用户消费行为分析\n",
    "   - 圣诞节前后被成功购买数量最多的前十个产品\n",
    "   - 圣诞节前后被退货数量最多的前十个产品"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "      <th>产品编号</th>\n",
       "      <th>产品描述</th>\n",
       "      <th>产品数量</th>\n",
       "      <th>订单日期和时间</th>\n",
       "      <th>单价（英镑）</th>\n",
       "      <th>客户编号</th>\n",
       "      <th>国家的名称</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>29016</th>\n",
       "      <td>C538684</td>\n",
       "      <td>21258</td>\n",
       "      <td>VICTORIAN SEWING BOX LARGE</td>\n",
       "      <td>-1</td>\n",
       "      <td>2010-12-14 09:26:00</td>\n",
       "      <td>12.75</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>-12.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29017</th>\n",
       "      <td>C538684</td>\n",
       "      <td>22946</td>\n",
       "      <td>WOODEN ADVENT CALENDAR CREAM</td>\n",
       "      <td>-1</td>\n",
       "      <td>2010-12-14 09:26:00</td>\n",
       "      <td>16.95</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>-16.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29018</th>\n",
       "      <td>C538684</td>\n",
       "      <td>22470</td>\n",
       "      <td>HEART OF WICKER LARGE</td>\n",
       "      <td>-1</td>\n",
       "      <td>2010-12-14 09:26:00</td>\n",
       "      <td>2.95</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>-2.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29021</th>\n",
       "      <td>538687</td>\n",
       "      <td>22961</td>\n",
       "      <td>JAM MAKING SET PRINTED</td>\n",
       "      <td>96</td>\n",
       "      <td>2010-12-14 09:50:00</td>\n",
       "      <td>1.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>120.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29022</th>\n",
       "      <td>538687</td>\n",
       "      <td>22666</td>\n",
       "      <td>RECIPE BOX PANTRY YELLOW DESIGN</td>\n",
       "      <td>24</td>\n",
       "      <td>2010-12-14 09:50:00</td>\n",
       "      <td>2.55</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>61.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42446</th>\n",
       "      <td>539988</td>\n",
       "      <td>22197</td>\n",
       "      <td>SMALL POPCORN HOLDER</td>\n",
       "      <td>2</td>\n",
       "      <td>2010-12-23 16:06:00</td>\n",
       "      <td>0.85</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>1.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42447</th>\n",
       "      <td>539988</td>\n",
       "      <td>22834</td>\n",
       "      <td>HAND WARMER BABUSHKA DESIGN</td>\n",
       "      <td>4</td>\n",
       "      <td>2010-12-23 16:06:00</td>\n",
       "      <td>2.10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>8.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42448</th>\n",
       "      <td>539988</td>\n",
       "      <td>84378</td>\n",
       "      <td>SET OF 3 HEART COOKIE CUTTERS</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-12-23 16:06:00</td>\n",
       "      <td>1.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42449</th>\n",
       "      <td>539988</td>\n",
       "      <td>84380</td>\n",
       "      <td>SET OF 3 BUTTERFLY COOKIE CUTTERS</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-12-23 16:06:00</td>\n",
       "      <td>1.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42452</th>\n",
       "      <td>539988</td>\n",
       "      <td>22854</td>\n",
       "      <td>CREAM SWEETHEART EGG HOLDER</td>\n",
       "      <td>2</td>\n",
       "      <td>2010-12-23 16:06:00</td>\n",
       "      <td>4.95</td>\n",
       "      <td>NaN</td>\n",
       "      <td>United Kingdom</td>\n",
       "      <td>9.90</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6866 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          订单编号   产品编号                               产品描述  产品数量  \\\n",
       "29016  C538684  21258         VICTORIAN SEWING BOX LARGE    -1   \n",
       "29017  C538684  22946       WOODEN ADVENT CALENDAR CREAM    -1   \n",
       "29018  C538684  22470              HEART OF WICKER LARGE    -1   \n",
       "29021   538687  22961             JAM MAKING SET PRINTED    96   \n",
       "29022   538687  22666    RECIPE BOX PANTRY YELLOW DESIGN    24   \n",
       "...        ...    ...                                ...   ...   \n",
       "42446   539988  22197               SMALL POPCORN HOLDER     2   \n",
       "42447   539988  22834        HAND WARMER BABUSHKA DESIGN     4   \n",
       "42448   539988  84378      SET OF 3 HEART COOKIE CUTTERS     1   \n",
       "42449   539988  84380  SET OF 3 BUTTERFLY COOKIE CUTTERS     1   \n",
       "42452   539988  22854        CREAM SWEETHEART EGG HOLDER     2   \n",
       "\n",
       "                  订单日期和时间  单价（英镑） 客户编号           国家的名称     销售额  \n",
       "29016 2010-12-14 09:26:00   12.75  NaN  United Kingdom  -12.75  \n",
       "29017 2010-12-14 09:26:00   16.95  NaN  United Kingdom  -16.95  \n",
       "29018 2010-12-14 09:26:00    2.95  NaN  United Kingdom   -2.95  \n",
       "29021 2010-12-14 09:50:00    1.25  NaN  United Kingdom  120.00  \n",
       "29022 2010-12-14 09:50:00    2.55  NaN  United Kingdom   61.20  \n",
       "...                   ...     ...  ...             ...     ...  \n",
       "42446 2010-12-23 16:06:00    0.85  NaN  United Kingdom    1.70  \n",
       "42447 2010-12-23 16:06:00    2.10  NaN  United Kingdom    8.40  \n",
       "42448 2010-12-23 16:06:00    1.25  NaN  United Kingdom    1.25  \n",
       "42449 2010-12-23 16:06:00    1.25  NaN  United Kingdom    1.25  \n",
       "42452 2010-12-23 16:06:00    4.95  NaN  United Kingdom    9.90  \n",
       "\n",
       "[6866 rows x 9 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 圣诞节前后的购物习惯\n",
    "#2010年12月14到2010年12月31的购买数据（商品销售最多）\n",
    "film_date\n",
    "shop_Christmas=film_date[film_date['订单日期和时间']>='2010-12-14']\n",
    "shop_Christmas=shop_Christmas[shop_Christmas['订单日期和时间']<='2010-12-31']\n",
    "# shop_Christmas.to_csv(\"111.csv\",encoding=\"gbk\")\n",
    "shop_Christmas\n",
    "# film_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>产品描述</th>\n",
       "      <th>产品数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GROW A FLYTRAP OR SUNFLOWER IN TIN</td>\n",
       "      <td>2592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HAND WARMER BABUSHKA DESIGN</td>\n",
       "      <td>2047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PACK OF 72 RETROSPOT CAKE CASES</td>\n",
       "      <td>1856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>PACK OF 12 LONDON TISSUES</td>\n",
       "      <td>1617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>72 SWEETHEART FAIRY CAKE CASES</td>\n",
       "      <td>1114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SMALL POPCORN HOLDER</td>\n",
       "      <td>1030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>PACK OF 60 PINK PAISLEY CAKE CASES</td>\n",
       "      <td>1015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>WORLD WAR 2 GLIDERS ASSTD DESIGNS</td>\n",
       "      <td>1011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>60 TEATIME FAIRY CAKE CASES</td>\n",
       "      <td>983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>RED TOADSTOOL LED NIGHT LIGHT</td>\n",
       "      <td>956</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 产品描述  产品数量\n",
       "0  GROW A FLYTRAP OR SUNFLOWER IN TIN  2592\n",
       "1         HAND WARMER BABUSHKA DESIGN  2047\n",
       "2     PACK OF 72 RETROSPOT CAKE CASES  1856\n",
       "3          PACK OF 12 LONDON TISSUES   1617\n",
       "4      72 SWEETHEART FAIRY CAKE CASES  1114\n",
       "5                SMALL POPCORN HOLDER  1030\n",
       "6  PACK OF 60 PINK PAISLEY CAKE CASES  1015\n",
       "7   WORLD WAR 2 GLIDERS ASSTD DESIGNS  1011\n",
       "8         60 TEATIME FAIRY CAKE CASES   983\n",
       "9       RED TOADSTOOL LED NIGHT LIGHT   956"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#圣诞节商品前十\n",
    "shop_Christmas_sales=shop_Christmas.groupby(shop_Christmas[\"产品描述\"],as_index=False)[\"产品数量\"].sum()\n",
    "shop_Christmas_sales=shop_Christmas_sales.sort_values(by=\"产品数量\",ascending=False)\n",
    "shop_Christmas_sales=shop_Christmas_sales.reset_index().drop(\"index\",axis=1).head(10)\n",
    "#全年商品前十\n",
    "shop_sales=film_date\n",
    "shop_sales=shop_sales.groupby(shop_sales[\"产品描述\"],as_index=False)[\"产品数量\"].sum()\n",
    "shop_sales=shop_sales.sort_values(by=\"产品数量\",ascending=False)\n",
    "shop_sales=shop_sales.reset_index().drop(\"index\",axis=1).head(10)\n",
    "shop_sales\n",
    "shop_Christmas_sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"83bb06ffb22c47409468bc740b9982fa\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_83bb06ffb22c47409468bc740b9982fa = echarts.init(\n",
       "                    document.getElementById('83bb06ffb22c47409468bc740b9982fa'), 'white', {renderer: 'canvas'});\n",
       "                var option_83bb06ffb22c47409468bc740b9982fa = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"GROW A FLYTRAP OR SUNFLOWER IN TIN\",\n",
       "                    \"value\": 2592\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"HAND WARMER BABUSHKA DESIGN\",\n",
       "                    \"value\": 2047\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"PACK OF 72 RETROSPOT CAKE CASES\",\n",
       "                    \"value\": 1856\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"PACK OF 12 LONDON TISSUES \",\n",
       "                    \"value\": 1617\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"72 SWEETHEART FAIRY CAKE CASES\",\n",
       "                    \"value\": 1114\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"SMALL POPCORN HOLDER\",\n",
       "                    \"value\": 1030\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"PACK OF 60 PINK PAISLEY CAKE CASES\",\n",
       "                    \"value\": 1015\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"WORLD WAR 2 GLIDERS ASSTD DESIGNS\",\n",
       "                    \"value\": 1011\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"60 TEATIME FAIRY CAKE CASES\",\n",
       "                    \"value\": 983\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"RED TOADSTOOL LED NIGHT LIGHT\",\n",
       "                    \"value\": 956\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"25%\",\n",
       "                \"55%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"79%\",\n",
       "                \"60%\"\n",
       "            ],\n",
       "            \"roseType\": \"radius\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"GROW A FLYTRAP OR SUNFLOWER IN TIN\",\n",
       "                \"HAND WARMER BABUSHKA DESIGN\",\n",
       "                \"PACK OF 72 RETROSPOT CAKE CASES\",\n",
       "                \"PACK OF 12 LONDON TISSUES \",\n",
       "                \"72 SWEETHEART FAIRY CAKE CASES\",\n",
       "                \"SMALL POPCORN HOLDER\",\n",
       "                \"PACK OF 60 PINK PAISLEY CAKE CASES\",\n",
       "                \"WORLD WAR 2 GLIDERS ASSTD DESIGNS\",\n",
       "                \"60 TEATIME FAIRY CAKE CASES\",\n",
       "                \"RED TOADSTOOL LED NIGHT LIGHT\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"2%\",\n",
       "            \"top\": \"15%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"2010\\u5e74\\u5723\\u8bde\\u8282\\u524d\\u540e\\u7684\\u70ed\\u9500\\u5546\\u54c1\\u524d\\u5341\\u540d\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_83bb06ffb22c47409468bc740b9982fa.setOption(option_83bb06ffb22c47409468bc740b9982fa);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x13b95e30>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pie=Pie().add(\n",
    "            \"\",\n",
    "            shop_Christmas_sales.values.tolist(),\n",
    "            radius=[\"25%\", \"55%\"],\n",
    "            center=[\"79%\", \"60%\"],\n",
    "            rosetype=\"radius\"\n",
    "        ).set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"2010年圣诞节前后的热销商品前十名\"),\n",
    "            legend_opts=opts.LegendOpts(\n",
    "                orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"\n",
    "            )\n",
    "        )\n",
    "pie.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"111273ffcb444e28809d9e0a7713704a\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_111273ffcb444e28809d9e0a7713704a = echarts.init(\n",
       "                    document.getElementById('111273ffcb444e28809d9e0a7713704a'), 'white', {renderer: 'canvas'});\n",
       "                var option_111273ffcb444e28809d9e0a7713704a = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u5546\\u54c1\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"WORLD WAR 2 GLIDERS ASSTD DESIGNS\",\n",
       "                    \"value\": 53215\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"ASSORTED COLOUR BIRD ORNAMENT\",\n",
       "                    \"value\": 35314\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"PACK OF 72 RETROSPOT CAKE CASES\",\n",
       "                    \"value\": 33409\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"POPCORN HOLDER\",\n",
       "                    \"value\": 30504\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"RABBIT NIGHT LIGHT\",\n",
       "                    \"value\": 27094\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"MINI PAINT SET VINTAGE \",\n",
       "                    \"value\": 25880\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"PACK OF 12 LONDON TISSUES \",\n",
       "                    \"value\": 25321\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"PACK OF 60 PINK PAISLEY CAKE CASES\",\n",
       "                    \"value\": 24163\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"BROCADE RING PURSE \",\n",
       "                    \"value\": 22960\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"VICTORIAN GLASS HANGING T-LIGHT\",\n",
       "                    \"value\": 21984\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 0,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"POPCORN HOLDER\",\n",
       "                \"BROCADE RING PURSE \",\n",
       "                \"RABBIT NIGHT LIGHT\",\n",
       "                \"MINI PAINT SET VINTAGE \",\n",
       "                \"PACK OF 12 LONDON TISSUES \",\n",
       "                \"VICTORIAN GLASS HANGING T-LIGHT\",\n",
       "                \"ASSORTED COLOUR BIRD ORNAMENT\",\n",
       "                \"WORLD WAR 2 GLIDERS ASSTD DESIGNS\",\n",
       "                \"PACK OF 60 PINK PAISLEY CAKE CASES\",\n",
       "                \"PACK OF 72 RETROSPOT CAKE CASES\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"WORLD WAR 2 GLIDERS ASSTD DESIGNS\": true,\n",
       "                \"ASSORTED COLOUR BIRD ORNAMENT\": true,\n",
       "                \"PACK OF 72 RETROSPOT CAKE CASES\": true,\n",
       "                \"POPCORN HOLDER\": true,\n",
       "                \"RABBIT NIGHT LIGHT\": true,\n",
       "                \"MINI PAINT SET VINTAGE \": true,\n",
       "                \"PACK OF 12 LONDON TISSUES \": true,\n",
       "                \"PACK OF 60 PINK PAISLEY CAKE CASES\": true,\n",
       "                \"BROCADE RING PURSE \": true,\n",
       "                \"VICTORIAN GLASS HANGING T-LIGHT\": true\n",
       "            },\n",
       "            \"show\": false,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u5168\\u5e74\\u5546\\u54c1\\u524d\\u5341\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_111273ffcb444e28809d9e0a7713704a.setOption(option_111273ffcb444e28809d9e0a7713704a);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x13b96610>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#漏斗图\n",
    "funnel=Funnel().add(\n",
    "        \"商品\",\n",
    "        shop_sales.values.tolist(),\n",
    "    ).set_global_opts(title_opts=opts.TitleOpts(title=\"全年商品前十\"),legend_opts=opts.LegendOpts(\n",
    "                is_show=False\n",
    "            ))\n",
    "funnel.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>产品描述</th>\n",
       "      <th>产品数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GROW A FLYTRAP OR SUNFLOWER IN TIN</td>\n",
       "      <td>2592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HAND WARMER BABUSHKA DESIGN</td>\n",
       "      <td>2047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PACK OF 72 RETROSPOT CAKE CASES</td>\n",
       "      <td>1856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>PACK OF 12 LONDON TISSUES</td>\n",
       "      <td>1617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>72 SWEETHEART FAIRY CAKE CASES</td>\n",
       "      <td>1114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SMALL POPCORN HOLDER</td>\n",
       "      <td>1030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>PACK OF 60 PINK PAISLEY CAKE CASES</td>\n",
       "      <td>1015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>WORLD WAR 2 GLIDERS ASSTD DESIGNS</td>\n",
       "      <td>1011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>60 TEATIME FAIRY CAKE CASES</td>\n",
       "      <td>983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>RED TOADSTOOL LED NIGHT LIGHT</td>\n",
       "      <td>956</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 产品描述  产品数量\n",
       "0  GROW A FLYTRAP OR SUNFLOWER IN TIN  2592\n",
       "1         HAND WARMER BABUSHKA DESIGN  2047\n",
       "2     PACK OF 72 RETROSPOT CAKE CASES  1856\n",
       "3          PACK OF 12 LONDON TISSUES   1617\n",
       "4      72 SWEETHEART FAIRY CAKE CASES  1114\n",
       "5                SMALL POPCORN HOLDER  1030\n",
       "6  PACK OF 60 PINK PAISLEY CAKE CASES  1015\n",
       "7   WORLD WAR 2 GLIDERS ASSTD DESIGNS  1011\n",
       "8         60 TEATIME FAIRY CAKE CASES   983\n",
       "9       RED TOADSTOOL LED NIGHT LIGHT   956"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shop_Christmas_sales=shop_Christmas.groupby(shop_Christmas[\"产品描述\"],as_index=False)[\"产品数量\"].sum()\n",
    "shop_Christmas_sales=shop_Christmas_sales.sort_values(by=\"产品数量\",ascending=False)\n",
    "shop_Christmas_sales=shop_Christmas_sales.head(10).reset_index().drop(\"index\",axis=1)\n",
    "shop_Christmas_sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>产品描述</th>\n",
       "      <th>产品数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOLD MINI TAPE MEASURE</td>\n",
       "      <td>-300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SMALLFOLKART BAUBLE CHRISTMAS DEC</td>\n",
       "      <td>-96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CACTI T-LIGHT CANDLES</td>\n",
       "      <td>-80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HYACINTH BULB T-LIGHT CANDLES</td>\n",
       "      <td>-80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>REGENCY CAKESTAND 3 TIER</td>\n",
       "      <td>-71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SILVER HANGING T-LIGHT HOLDER</td>\n",
       "      <td>-65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>ASSTD DESIGN 3D PAPER STICKERS</td>\n",
       "      <td>-60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>VICTORIAN GLASS HANGING T-LIGHT</td>\n",
       "      <td>-51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>ANGEL DECORATION STARS ON DRESS</td>\n",
       "      <td>-48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>COOK WITH WINE METAL SIGN</td>\n",
       "      <td>-48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                产品描述  产品数量\n",
       "0            GOLD MINI TAPE MEASURE   -300\n",
       "1  SMALLFOLKART BAUBLE CHRISTMAS DEC   -96\n",
       "2              CACTI T-LIGHT CANDLES   -80\n",
       "3      HYACINTH BULB T-LIGHT CANDLES   -80\n",
       "4           REGENCY CAKESTAND 3 TIER   -71\n",
       "5      SILVER HANGING T-LIGHT HOLDER   -65\n",
       "6     ASSTD DESIGN 3D PAPER STICKERS   -60\n",
       "7    VICTORIAN GLASS HANGING T-LIGHT   -51\n",
       "8    ANGEL DECORATION STARS ON DRESS   -48\n",
       "9         COOK WITH WINE METAL SIGN    -48"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shop_Christmas_down=shop_Christmas[shop_Christmas[\"产品数量\"]<0]\n",
    "shop_Christmas_down=shop_Christmas_down.groupby(shop_Christmas_down[\"产品描述\"],as_index=False)[\"产品数量\"].sum()\n",
    "shop_Christmas_down=shop_Christmas_down.sort_values(by=\"产品数量\",ascending=True)\n",
    "shop_Christmas_down=shop_Christmas_down.head(10).reset_index().drop(\"index\",axis=1)\n",
    "shop_Christmas_down"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
